<template src="./template.html">

</template>

<script>
    import { loginService } from "@/services";
    import { Toast } from "mint-ui";
    export default {
        props:{
            switchOn:Boolean,
            perviewOn:Boolean,
            updateData:String,
        },
        data() {
            // var serverUrl = 'static/temp/template9/'
            var serverUrl = 'http://skyforest.static.elab-plus.com/temp/template8/';
            return {
                tel:'',  //项目关联手机号
                appcodeUrl:'',
                customerId:'',
                uploading:false,
                isSend:'', //是否跟顾问聊过天
                isshow:true,
                disabled:false,
                serverUrl:serverUrl,
                obj:{
                    text1:'',
                    text2:'',
                    text3:'',
                    text4:'',
                    text5:'',
                    text6:'',
                    text7:'',
                    text8:'',
                    text9:'',
                    text10:'',
                    text11:'',
                    text12:'',
                    text13:'',
                    text14:'',
                    text15:'',
                    logoUrl:`${serverUrl}LOGO.png`,
                    picUrl1:`${serverUrl}img1.png`,
                    picUrl2:[`${serverUrl}img2.png`,`${serverUrl}img2.png`,`${serverUrl}img2.png`],
                    picUrl3:[`${serverUrl}img3.png`,`${serverUrl}img3.png`,`${serverUrl}img3.png`],
                    picUrl4:[`${serverUrl}img4.png`,`${serverUrl}img4.png`,`${serverUrl}img4.png`],
                    //picUrl2:[`${serverUrl}pic1.png`,`${serverUrl}pic1.png`,`${serverUrl}pic1.png`,`${serverUrl}pic1.png`,`${serverUrl}pic1.png`,`${serverUrl}pic1.png`],
                    //picUrl3:[`${serverUrl}pic2.png`,`${serverUrl}pic2.png`,`${serverUrl}pic2.png`,`${serverUrl}pic2.png`,`${serverUrl}pic2.png`,`${serverUrl}pic2.png`],
                    //picUrl4:[`${serverUrl}pic3.png`,`${serverUrl}pic3.png`,`${serverUrl}pic3.png`,`${serverUrl}pic3.png`,`${serverUrl}pic3.png`,`${serverUrl}pic3.png`],
                    picUrl5:`${serverUrl}img5.png`,
                    picUrl6:`${serverUrl}img6.png`,
                    picUrl7:`${serverUrl}img7.png`,
                    picUrl8:[`${serverUrl}img8.png`,`${serverUrl}img8.png`,`${serverUrl}img8.png`],
                    picUrl9:[`${serverUrl}img9.png`,`${serverUrl}img9.png`,`${serverUrl}img9.png`],
                    picUrl10:`${serverUrl}img10.png`,
                    picUrl11:[`${serverUrl}img11.png`,`${serverUrl}img11.png`,`${serverUrl}img11.png`],
                }
            }
        },
        mounted() {
            this.customerId = localStorage.getItem('localCustomerId');
            this.appcodeUrl=localStorage.getItem('_appQrcode');
            this.tel=localStorage.getItem('_projectTel');
            if(this.updateData){
                this.obj =JSON.parse( this.updateData)
            }
        },
        watch:{
            switchOn(val){
                if(val){
                    this.$emit('com',this.obj)
                }
            },
            perviewOn(val){
                this.disabled=val;
                this.isshow=!val;
            },
            updateData(val){
                if(val){
                    val=JSON.parse(val);
                    this.obj = val;
                }
            }
        },
        methods: {
            async doUpload(evt,val){
                console.log(val)
                let files=evt.target.files;
                // if(files.length===0){
                //     Toast('请选择需要上传的图片');
                //     return
                // }
                let file = files[0];
                if(!file){
                    return false;
                }
                if(!file.type.match('image.*')){
                    Toast('请选择图片');
                    return
                }
                if (file.size > 0 && file.size > 5242880) {
                    this.$message.warning('请选小于5M的图片');
                    return;
                }
                this.uploading=true;
                let form = new FormData();
                form.append('type','qiniu_upload');
                form.append('folder','template');
                form.append('uploadFile',file)
                form.append('fileName',file.name)
                let result=await loginService.uploadFile(form);
                console.log(result,'gggggg')
                if(result.data.success){
                    this.uploading=false;
                    // console.log(result);
                    console.log(this.obj[val])
                    this.obj[val]=result.data.single.filepath;
                    console.log(this.obj, this.obj[val])
                    // console.log(this.Imgurl)
                    Toast('图片上传成功')
                }else{
                    Toast('图片上传失败');
                }
            },
            async doUpload2(evt,val){
                let files=evt.target.files;
                if(files.length>3){
                    Toast('上传最多不能超过3张图片哦');
                    return
                }
                let file = files[0];
                if(files.length==0){
                    return false;
                }
                // var imageFile = new Array();
                this.uploading=true;
                this.obj[val]=[];
                for(var i = 0; i<files.length; i++){
                    if(files[i].size > 0 && files[i].size > 5242880){
                        Toast('第'+(i+1)+'张图片请选择小于5M的图片');
                        return
                    }
                    // console.log(files[i].name);
                    let form = new FormData();
                    form.append('type','qiniu_upload');
                    form.append('folder','template');
                    form.append('uploadFile',files[i]);
                    form.append('fileName', files[i].name);
                    let result=await loginService.uploadFile(form);
                    if(result.data.success){
                        this.uploading=false;
                        this.obj[val].push(
                             result.data.single.filepath
                        );

                        console.log(this.obj[val]);
                    }else{
                        Toast('图片上传失败');
                    }
                }
            },
        }
    }
</script>

<style lang="scss" scoped>
  @import "./style.scss"
</style>
